var orderInf;
apiready = function() {
	api.showProgress();
	var orderId = api.pageParam.orderId;
	if (!orderId) {
		api.closeWin();
		return;
	}
	$api.getUserInf(function(userInf) {
		$api.do_post('/api/pgroup/orderinfo', {
			body: $api.jsonToStr({
				account: userInf.account,
				id: orderId
			})
		}, function(ret) {
			orderInf = ret;
			$('#number').text(ret.orderNo);
			$('#status').text(ret.status);
			$('#receiver').text(ret.receiver);
			$('#phone').text(ret.phone);
			$('#address').text(ret.address);
			$('#proNames').text(ret.proNames);
			$('#price').text('￥' + ret.price);
			$('#buyNum').text(ret.buyNum);
			$('#prototal').text(ret.prototal || 0)
			$('#postage').text(ret.postage || 0)
			$('.total').text("￥" + ret.total);
			$api.getNetPicPath(ret.proimg, function(picUrl) {
				$('#proimg').attr('src', picUrl);
			})

			if (ret.status != "待支付") {
				$("#btnPay").remove();
			}
			// var html = $('.view').html();
			// var decHtml = htmlDe(html);
			// var re = _.template(decHtml);
			// var reHtml = re(ret);
			// $body.html(reHtml);
		});

	});
};

$('.toGroupInf').on('click', function() {
	$api.mOpenWin('groupInf', 'group_info.html', {
		id: orderInf.proids
	});
})



$("#btnPay").click(function() {
	api.showProgress();
	//支付宝  手机版
	//if(confirm("支付宝(手机版)处于调试阶段,可能无法完成支付,是否继续?")){
	// $("#payfrom").attr('action', '/alipay/wap');
	var aliPay = api.require('aliPay');
	aliPay.pay({
		subject: '支付',
		body: '支付宝支付',
		amount: orderInf.total,
		tradeNO: orderInf.orderNo
	}, function(ret, err) {
		api.hideProgress();
		switch (ret.code) {
			case "9000":
				{
					api.alert({
						title: '支付结果',
						msg: '支付成功',
						buttons: ['确定']
					});
					api.closeWin();
					break;
				}
			case "6001":
				{
					$api.toastMsg("支付已取消");
					break;
				}
			default:
				{
					api.alert({
						title: '支付结果',
						msg: ret.code + " 错误内容：" + ret.statusMessage,
						buttons: ['确定']
					});
				}

		}
	});

})